package com.ruoyi.web.controller.fund;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cost.domain.FundCostT;
import com.ruoyi.costBatchDetail.domain.HouseBatchDetailT;
import com.ruoyi.costBatchDetail.service.IHouseBatchDetailTService;
import com.ruoyi.data.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 户管理Controller
 * 
 * @author lijie
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/fund/costBatchDetail")
public class HouseBatchDetailTController extends BaseController
{
    @Autowired
    private IHouseBatchDetailTService houseBatchDetailTService;

    /**
     * 查询户管理列表
     */
   @GetMapping("/list")
    public TableDataInfo list(HouseBatchDetailT houseBatchDetailT) throws Exception {
        startPage();
        List<HouseBatchDetailT> list = new ArrayList<HouseBatchDetailT>();
        if(houseBatchDetailT.getBatchId()!=null){
            list = houseBatchDetailTService.selectBatchDetailTList(houseBatchDetailT);
        }
       if(list.size()>0){
           for (HouseBatchDetailT vo : list){
               vo.setUserName(MD5.decrypt(vo.getUserName()));
           }
       }
        return getDataTable(list);
    }
    /**
     * 查询户管理列表
     */
    @GetMapping("/listBatchDetail")
    public TableDataInfo listBatchDetail(HouseBatchDetailT houseBatchDetailT) throws Exception {
        startPage();
        List<HouseBatchDetailT> list = new ArrayList<HouseBatchDetailT>();
        if(houseBatchDetailT.getBatchId()!=null){
            list = houseBatchDetailTService.selectBatchDetailTByBatchId(Long.parseLong(houseBatchDetailT.getBatchId()));
        }
        if(list.size()>0){
            for (HouseBatchDetailT vo : list){
                vo.setUserName(MD5.decrypt(vo.getUserName()));
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出户管理列表
     */
   @Log(title = "户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseBatchDetailT houseBatchDetailT)
    {
        List<HouseBatchDetailT> list = houseBatchDetailTService.selectBatchDetailTList(houseBatchDetailT);
        ExcelUtil<HouseBatchDetailT> util = new ExcelUtil<HouseBatchDetailT>(HouseBatchDetailT.class);
        util.exportExcel(response, list, "户管理数据");
    }

    /**
     * 批量缴费
     */
   @Log(title = "批量缴费管理", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/insertCostDetail/{houseIds}/{batchId}")
    public AjaxResult insertCost(@PathVariable("houseIds") String[] houseIds,@PathVariable("batchId") Long batchId)
    {
        FundCostT fundCostT = new FundCostT();
        fundCostT.setCreater(getUsername());
        return toAjax(houseBatchDetailTService.insertBatchDetail(fundCostT,houseIds,batchId));
    }

   @Log(title = "批量缴费管理", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/deleteCostDetail/{houseIds}/{batchId}")
    public AjaxResult deleteCost(@PathVariable("houseIds") String[] houseIds,@PathVariable("batchId") Long batchId)
    {
        return toAjax(houseBatchDetailTService.deleteBatchDetail(houseIds,batchId));
    }

    /**
     * 获取批量明细缴费详细信息
     */
    @GetMapping(value = "/{batchId}")
    public TableDataInfo getInfo(@PathVariable("batchId") Long batchId)
    {
        startPage();
        List<HouseBatchDetailT> list = new ArrayList<HouseBatchDetailT>();
        list = houseBatchDetailTService.selectBatchDetailTByBatchId(batchId);
        return getDataTable(list);
    }

    @GetMapping(value = "/getDetail/{batchId}")
    public TableDataInfo getInfoDetail(@PathVariable("batchId") Long batchId)
    {
        startPage();
        List<HouseBatchDetailT> list = new ArrayList<HouseBatchDetailT>();
        list = houseBatchDetailTService.selectBatchTByBatchId(batchId);
        return getDataTable(list);
    }


}
